package manage.controller;

import core.controller.BaseController;
import core.domain.ListDataInfo;
import core.domain.Result;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import manage.domain.question.dto.QuestionAddDTO;
import manage.domain.question.dto.QuestionEditDTO;
import manage.domain.question.dto.QuestionQueryDTO;
import manage.domain.question.vo.QuestionDetailVO;
import manage.domain.question.vo.QuestionVO;
import manage.service.IQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/question")
@Tag(name = "题目管理")
public class QuestionController extends BaseController {

    @Autowired
    private IQuestionService questionService;
    @GetMapping("/list")
    public ListDataInfo list(QuestionQueryDTO questionQueryDTO) {
        log.info("QuestionController -> list {}", questionQueryDTO);
        List<QuestionVO> list = questionService.list(questionQueryDTO);
        return toListDataInfo(list);
    }

    @PostMapping("/add")
    public Result<Void> add(@RequestBody @Validated QuestionAddDTO questionAddDTO) {
        log.info("QuestionController -> add {}", questionAddDTO);
        return toResult(questionService.add(questionAddDTO));
    }

    @GetMapping("/detail")
    public Result<QuestionDetailVO> detail(Long questionId) {
        log.info("QuestionController -> detail {}", questionId);
        return Result.success(questionService.detail(questionId));
    }

    @PutMapping("/edit")
    public Result<Void> edit(@RequestBody @Validated QuestionEditDTO questionEditDTO) {
        log.info("QuestionController -> edit {}", questionEditDTO);
        return toResult(questionService.edit(questionEditDTO));
    }

    @DeleteMapping("/delete")
    public Result<Void> delete(Long questionId) {
        log.info("QuestionController -> delete {}", questionId);
        return toResult(questionService.delete(questionId));
    }
}
